
Public Class FdapPortService

    Public Shared Function GetRefPort(ByVal pid As String, ByVal netid As Integer, ByVal portno As Integer) As Integer

        Dim strSql As String = String.Format("select fdapPortNo from fdapportinfo where projectID ='{0}' and netid ='{1}' and portno='{2}' ", pid, netid, portno)


        Dim obj As Object
        obj = SqlHelper.ExecuteScalar(strSql, Nothing)

        If obj Is Nothing OrElse IsDBNull(obj) Then
            Return 0
        Else
            Return CInt(obj)
        End If

    End Function

    Public Shared Function DelRefPort(ByVal pid As String, ByVal netid As Integer, ByVal portno As Integer) As Integer

        Dim tic As New TBCC.Utility.TranstrationItem
        Dim strSql As String = String.Format("delete from fdapportinfo where projectID ='{0}' and netid ={1} and portno={2} ", pid, netid, portno)


        tic.Add(strSql, Nothing)


        Return SqlHelper.ExecuteTranstration(tic)

    End Function

    Public Shared Function InserRefPort(ByVal pid As String, ByVal netid As Integer, ByVal portno As Integer, ByVal fdapportno As Integer) As Integer
        Dim tic1 As New TBCC.Utility.TranstrationItem
        Dim strSql As String = String.Format("insert into fdapportinfo (ProjectID,NetID,PortNo,fdapPortNo) values('{0}','{1}','{2}','{3}')  ", pid, netid, portno, fdapportno)


        tic1.Add(strSql, Nothing)
        SqlHelper.ExecuteTranstration(tic1)
    End Function

    Public Shared Function GetAllData() As List(Of FdapPortInfoClass)
        Dim list As IList(Of FdapPortInfoClass)
        list = New List(Of FdapPortInfoClass)

        Dim strSql = String.Format("select * from fdapportinfo where projectID ='{0}'", MainForm.pi.ProjectID)

        Dim dt As DataSet
        dt = SqlHelper.ExecuteDataset(strSql, Nothing)

        For Each r As DataRow In dt.Tables(0).Rows
            Dim p As New FdapPortInfoClass
            p.ProjectID = SqlHelper.GetDbData(r("ProjectID"))
            p.NetId = SqlHelper.GetDbData(r("NetID"))
            p.PortNo = SqlHelper.GetDbData(r("PortNo"))
            p.fdapPortNo = SqlHelper.GetDbData(r("fdapPortNo"))
          
            list.Add(p)
        Next

        Return list
    End Function


End Class
